package com.alennus.blog.rabbitMq.spring_rabbit.topic;

import com.alennus.blog.rabbitMq.spring_rabbit.config.RabbitConfig;
import com.alennus.blog.rabbitMq.spring_rabbit.domain.User;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Created by pactera on 2018/9/25.
 *
 * topic ExChange示例
 * topic 是RabbitMQ中最灵活的一种方式，可以根据binding_key自由的绑定不同的队列
 * 首先对topic规则配置，这里使用两个队列来测试（也就是在Application类中创建和绑定的topic.message和topic.messages两个队列），
 * 其中topic.message的bindting_key为
 *“topic.message”，topic.messages的binding_key为“topic.#”；
 * key 路由严格区分大小写
 *
 *
 */
@Component
public class ProductTopicSender {


    @Autowired
    public RabbitTemplate rabbitTemplate;

    public void send() {
        User user = new User();
        user.setName("冯奕珂");
        user.setPass("冯奕珂密码");
        String msg1 = "I am topic.mesaage msg======"+user.toString();
        System.out.println("sender1 : " + msg1);
        this.rabbitTemplate.convertAndSend(RabbitConfig.EXCHANGE_TOPIC_NAME, RabbitConfig.QUEUE_TOPIC_MESSAGE_NAME, msg1);
        user.setName("李娟");
        user.setPass("李娟密码");
        String msg2 = "I am topic.mesaages msg########" + user;
        System.out.println("sender2 : " + msg2);
        this.rabbitTemplate.convertAndSend(RabbitConfig.EXCHANGE_TOPIC_NAME, RabbitConfig.QUEUE_TOPIC_MESSAGES_NAME, msg2);
    }


}
